package com.winit.cloudlink.demo.core.tms;

import java.util.Properties;

import com.winit.cloudlink.Cloudlink;
import com.winit.cloudlink.Configuration;
import com.winit.cloudlink.command.Command;
import com.winit.cloudlink.demo.core.OrderCreateInfo;
import com.winit.cloudlink.demo.core.PickupInfo;
import com.winit.cloudlink.message.Message;

public class StartupTmsCN {

    public static void main(String[] args) {
        Properties properties = new Properties();
        properties.setProperty("appId", "TEST1.TEST.ALL.CNR");
        properties.setProperty("appType", "TEST");
        properties.setProperty("zone", "CNR");
        properties.setProperty("mq", "admin:admin123@172.16.2.176:5672");
        Cloudlink cloudlink = new Configuration().configure(properties).getCloudlink();

        // 注册指令执行函数
        cloudlink.registerCommandExecutor(new PickupCommandExecutor());

        cloudlink.registerCommandCallback(new PickupCallback());

        cloudlink.registerMessageHandler(new OrderCreateMessageHandler());

        PickupInfo pickupInfo = new PickupInfo();
        pickupInfo.setArea("AAAA");
        Command<PickupInfo> command = cloudlink.newCommandBuilder()
                .commandName(PickupInfo.COMMAND_NAME)
                .payload(pickupInfo)
                .toAppId("TEST1.TEST.ALL.CNR")
                .build();
        cloudlink.commitCommand(command);

        command = cloudlink.newCommandBuilder()
                .commandName(PickupInfo.COMMAND_NAME,"1")
                .payload(pickupInfo)
                .toAppId("TEST1.TEST.ALL.CNR")
                .build();
        cloudlink.commitCommand(command);

        OrderCreateInfo info = new OrderCreateInfo();
        info.setOrderId("BBBB");
        Message<OrderCreateInfo> message = cloudlink.newMessageBuilder()
                .direct("TEST1.TEST.ALL.CNR", OrderCreateInfo.COMMAND_NAME, info).build();
        cloudlink.sendMessage(message);

        info = new OrderCreateInfo();
        info.setOrderId("CCCCC");
        message = cloudlink.newMessageBuilder()
                .direct("TEST1.TEST.ALL.CNR", OrderCreateInfo.COMMAND_NAME, "2", info).build();
        cloudlink.sendMessage(message);

    }
}
